package com.along.dev.rbac.controller;

import com.along.dev.rbac.dto.DeptDTO;
import com.along.dev.rbac.entity.Dept;
import com.along.dev.rbac.entity.LoadData;
import com.along.dev.rbac.qo.DeptQO;
import com.along.dev.rbac.service.DeptService;
import com.along.utility.common.response.GeneralResult;
import com.along.utility.common.response.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;


/*
 * @Author: liujinyi
 * @DateTime: 2024/12/26 9:46
 */
@CrossOrigin
@RestController
@RequestMapping("/rbac/dept")
public class DeptController {
    @Autowired
    private DeptService deptService;



    @GetMapping("test")
    public String test(){
        return "success!";
    }

    @PostMapping("/find")
    public PageResult<DeptDTO> find(@RequestBody DeptQO deptQO) {
        return PageResult.success(deptService.find(deptQO,deptQO.getPage(),deptQO.getRows()));
    }

    @PostMapping("/exclude")
    public GeneralResult<List<Dept>> exclude(@RequestBody Integer deptId) {
        return GeneralResult.success(deptService.exclude(deptId));
    }

    @PostMapping("/save")
    public GeneralResult<DeptDTO> save(@RequestBody DeptDTO deptDTO) {
        deptService.save(deptDTO);
        return GeneralResult.success();
    }

    @PostMapping("/update")
    public GeneralResult<DeptDTO> update(@RequestBody DeptDTO deptDTO) {
        deptService.update(deptDTO);
        return GeneralResult.success();
    }

    @PostMapping("/delete")
    public GeneralResult<DeptDTO> delete(@RequestBody DeptDTO deptDTO) {
        deptService.delete(deptDTO);
        return GeneralResult.success();
    }

    @PostMapping("/commFindByName/{deptId}")
    public List<Dept> commFindByName(@PathVariable("deptId") Long deptId) {
        return deptService.commFindByName(deptId);
    }


    @GetMapping("/sample")
    public LoadData getSampleData() {
        // 模拟从数据库查询的数据
        // 注意：实际值可能有更多小数位
        return new LoadData(
                BigDecimal.valueOf(0.1),
                BigDecimal.valueOf(0),
                BigDecimal.valueOf(90.001)
        );
    }
}
